package com.ruoyi.project.module.shao;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.HeDepartment;
import com.ruoyi.project.domain.HeEventReport;
import com.ruoyi.project.service.IHeDepartmentService;
import com.ruoyi.project.service.IHeEventReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科室统计Controller
 * 
 * @author ruoyi
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/shao/department")
public class ShaoDepartmentController extends BaseController
{
    @Autowired
    private IHeDepartmentService heDepartmentService;
    @Autowired
    private IHeEventReportService heEventReportService;
    /**
     * 查询科室统计列表
     */
//    @RequiresPermissions("project:department:list")
    @GetMapping("/list")
    public TableDataInfo list(HeDepartment heDepartment)
    {
        startPage();
        List<HeDepartment> list = heDepartmentService.selectHeDepartmentList(heDepartment);
        for(int i=0;i<list.size();i++){
            HeEventReport heEventReport=new HeEventReport();
            String DepartmentNumber= list.get(i).getDepartmentNumber();
            heEventReport.setReportDepartment(DepartmentNumber);
            List<HeEventReport > tjList=heEventReportService.selectHeEventReportList(heEventReport);
            heEventReport.setReportDepartment(null);
            heEventReport.setReviewDepartment(DepartmentNumber);
            List<HeEventReport > clList=heEventReportService.selectHeEventReportList(heEventReport);
            heEventReport.setReviewDepartment(null);
            heEventReport.setSupportDepartmentOne(DepartmentNumber);
            List<HeEventReport > xzList=heEventReportService.selectHeEventReportListBySupportDepartment(heEventReport);
            list.get(i).setDepartmentProcessing(Long.valueOf(clList.size()));
            list.get(i).setDepartmentCommits(Long.valueOf(tjList.size()));
            list.get(i).setDepartmentAssistance(Long.valueOf(xzList.size()));
        }
        return getDataTable(list);
    }

    /**
     * 导出科室统计列表
     */
//    @RequiresPermissions("project:department:export")
    @Log(title = "科室统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeDepartment heDepartment)
    {
        List<HeDepartment> list = heDepartmentService.selectHeDepartmentList(heDepartment);
        ExcelUtil<HeDepartment> util = new ExcelUtil<HeDepartment>(HeDepartment.class);
        util.exportExcel(response, list, "科室统计数据");
    }

    /**
     * 获取科室统计详细信息
     */
//    @RequiresPermissions("project:department:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(heDepartmentService.selectHeDepartmentById(id));
    }

    /**
     * 新增科室统计
     */
//    @RequiresPermissions("project:department:add")
    @Log(title = "科室统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeDepartment heDepartment)
    {
        return toAjax(heDepartmentService.insertHeDepartment(heDepartment));
    }

    /**
     * 修改科室统计
     */
//    @RequiresPermissions("project:department:edit")
    @Log(title = "科室统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeDepartment heDepartment)
    {
        return toAjax(heDepartmentService.updateHeDepartment(heDepartment));
    }

    /**
     * 删除科室统计
     */
//    @RequiresPermissions("project:department:remove")
    @Log(title = "科室统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(heDepartmentService.deleteHeDepartmentByIds(ids));
    }
}
